package com.parkinglot.controller;

import com.parkinglot.biz.CarParkActiveStatistics;
import com.parkinglot.biz.StatisticsContext;
import com.parkinglot.core.Result;
import com.parkinglot.enumeration.DateTypeEnum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("carParkActiveStatistics")
public class CarParkActiveStatisticsController {
    @Resource
    CarParkActiveStatistics bizCarParkActiveStatistics;

    @GetMapping("yesterDayStatistics")
    public Result yesterDayStatistics(String garageNumber) {
        StatisticsContext context = new StatisticsContext(DateTypeEnum.YESTERDAY);
        context.setGarageNumber(garageNumber);
        bizCarParkActiveStatistics.execute(context);
        return Result.success(context.getResult());
    }

    @GetMapping("lastWeekStatistics")
    public Result lastWeekStatistics(String garageNumber) {
        StatisticsContext context = new StatisticsContext(DateTypeEnum.LASTWEEK);
        context.setGarageNumber(garageNumber);
        bizCarParkActiveStatistics.execute(context);
        return Result.success(context.getResult());
    }

    @GetMapping("lastMonthStatistics")
    public Result lastMonthStatistics(String garageNumber) {
        StatisticsContext context = new StatisticsContext(DateTypeEnum.LASTMONTH);
        context.setGarageNumber(garageNumber);
        bizCarParkActiveStatistics.execute(context);
        return Result.success(context.getResult());
    }


}
